package pl.matt.dao.impl;

import java.util.Collection;
import java.util.List;

import pl.matt.dao.FrameDao;
import pl.matt.model.Frame;
import pl.matt.model.Video;

public class HibernateFrameDao extends HibernateAbstractEntityDao<Frame> implements FrameDao {

	//@SuppressWarnings("unused")
	private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(HibernateFrameDao.class);
	
	protected HibernateFrameDao() {
		super(Frame.class);
	}

	@Override
	public int deleteByVideo(Video video) {
		String hql = "DELETE FROM " + getEntityClass().getName() + " e WHERE e.video.id = ?";
		LOG.debug(hql + " <-- hql");
		return getHibernateTemplate().bulkUpdate(hql, video.getId());
	}

	@SuppressWarnings("unchecked")
	@Override
	public Collection<Frame> findByVideoName(String videoName) {
		return getHibernateTemplate().findByNamedQuery("Frame.findByVideoName", videoName);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Frame> findByVideoNameOrderByNumber(String videoName) {
		return getHibernateTemplate().findByNamedQuery("Frame.findByVideoNameOrderByNumber", videoName);
	}

}
